package com.kjtpay.design_pattern.visitor;

import java.util.ArrayList;

/**
 * 对象结构；ObjectStructure；对象的结合，并统一调用对象的accept方法；
 */
class ObjectStructure {
    private ArrayList<Person> elements = new ArrayList<Person>();

    // 增加
    public void attach(Person element) {
        elements.add(element);
    }

    // 移除
    public void detach(Person element) {
        elements.remove(element);
    }

    // 显示
    public String display(Action visitor) {
        String message = "";
        for (Person element:
             elements) {
            message += element.accept(visitor) + "\n";
        }
        return message;
    }
}
